package com.rambo.baselib;

import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.rambo.baselib.bean.ToolbarHolder;
import ohos.aafwk.ability.fraction.FractionAbility;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;
import ohos.agp.utils.Color;
import ohos.agp.window.service.WindowManager;

/**
 * Fraction 容器
 */
public class BaseFractionAbility extends FractionAbility {
    public BottomNavigationBar bottomNavBar;
    protected ToolbarHolder toolbarHolder = new ToolbarHolder();

    @Override
    protected void onStart(Intent intent) {
        //状态栏颜色
        getWindow().setStatusBarColor(Color.getIntColor("#177EE6"));
        getWindow().setStatusBarVisibility(Component.VISIBLE);
        super.onStart(intent);
        ComponentContainer rootComponent = (ComponentContainer) LayoutScatter.getInstance(this).parse(ResourceTable.Layout_ability_fraction_base, null, false);
        StackLayout toolbarContainer = (StackLayout) rootComponent.findComponentById(ResourceTable.Id_toolbar_container);
        if (isToolbarVisible() && getToolbarLayoutResId() > 0) {
            Component toolbar = LayoutScatter.getInstance(this).parse(getToolbarLayoutResId(), null, false);
            toolbarContainer.addComponent(toolbar, new StackLayout.LayoutConfig(StackLayout.LayoutConfig.MATCH_PARENT,
                    StackLayout.LayoutConfig.MATCH_PARENT));
            toolbarContainer.setVisibility(Component.VISIBLE);
            toolbarHolder.bindToolbarHolder(toolbar);
            toolbarHolder.setClickedListener(ResourceTable.Id_toolbar_iv_back, new Component.ClickedListener() {
                @Override
                public void onClick(Component component) {
                    onBackPressed();
                }
            });
        }
        StackLayout tabContainer = (StackLayout) rootComponent.findComponentById(ResourceTable.Id_tabLayout_container);
        if (isTabVisible()) {
            tabContainer.setVisibility(Component.VISIBLE);
        }
        StackLayout fractionContainer = (StackLayout) rootComponent.findComponentById(ResourceTable.Id_fraction_container);
        bottomNavBar = (BottomNavigationBar) rootComponent.findComponentById(ResourceTable.Id_bottom_bar);
        if (isBottomNavBarVisible()) {
            bottomNavBar.setVisibility(Component.VISIBLE);
        }
        setUIContent(rootComponent);
    }

    /**
     * toolbar 的布局
     *
     * @return
     */
    protected int getToolbarLayoutResId() {
        return ResourceTable.Layout_componet_toolbar;
    }

    /**
     * 是否启用toolbar
     *
     * @return
     */
    protected boolean isToolbarVisible() {
        return true;
    }

    /**
     * 是否启用Tab
     *
     * @return
     */
    protected boolean isTabVisible() {
        return false;
    }

    /**
     * 是否启用BottomNavBar
     *
     * @return
     */
    protected boolean isBottomNavBarVisible() {
        return false;
    }


}
